import java.util.*;

public class Soultion {
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for(int i = 0;i < pushV.length;i++){
            stack.push(pushV[i]);
            while(!stack.isEmpty() && stack.peek() == popV[j]){
                j++;
                stack.pop();
            }
        }
        return stack.empty();
    }
}
